package likou.tanxin;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/11/10 09:03
 */
public class _921 {
    public int minAddToMakeValid(String S) {
        int daan = 0;
        int left = 0;
        for (char now : S.toCharArray()) {
            if (now == '(') {
                left++;
                continue;
            }
            if (left == 0 && now == ')') {
                daan++;
            } else if (left != 0 && now == ')') {
                left--;
            }
        }
        daan+=left;
        return daan;
    }
}
